<template>
  <el-select :value="value" @change="onChange">
    <el-option :value="str ? `${item.value}` : item.value" :label="item.label" v-for="(item, index) in yearOptions"></el-option>
  </el-select>
</template>

<script>
export default {
  name: 'YearSelect',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: {
      default: null
    },
    str: {
      default: false,
      type: Boolean
    }
  },
  data() {
    return {
      currentYear: new Date().getFullYear()
    }
  },
  computed: {
    yearOptions() {
      const data = []
      for (let i = this.currentYear; i >= 2000; i--) {
        data.push({
          label: `${i}-${i + 1}学年`,
          value: i
        })
      }
      return data
    }
  },
  methods: {
    onChange(data) {
      this.$emit('change', data)
    }
  }
}
</script>

<style scoped>

</style>
